package com.itcast.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	
	/**
	 * 把String类型转换成Date类型
	 * @param time
	 * @param format
	 * @return
	 */
	public static Date TimeConversion(String time, String format) {
		SimpleDateFormat sfFormat = new SimpleDateFormat(format);
		try {
			time = time.replace("T"," ");
			//time = time.substring(0, time.indexOf("T"));
			Date date = sfFormat.parse(time);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Integer interceptLastChar(Date time) {
		SimpleDateFormat sfFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String times = sfFormat.format(time);
		times = times.substring(times.length() - 1, 1);
		return Integer.valueOf(times);
	}

}
